Skip to content

feat(panos): add LLDP port discovery to PAN-OS inspect interface - #2564

Open
khackworth wants to merge 12 commits into
mainfrom
panos-inspect-lldp-ports
Open

khackworth wants to merge 12 commits into
mainfrom
panos-inspect-lldp-ports

Conversation

@khackworth

@khackworth khackworth commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements automatic LLDP neighbor discovery during PAN-OS device inspection to populate port MAC addresses and local_link_connection data.

Changes

  • panos_inspect.py: Add _discover_and_update_ports() to enable LLDP, wait for neighbor discovery, and update ports
  • panos_api.py: Add API methods for config management, commit operations, and LLDP neighbor retrieval

Testing

Draft PR to build container image for testing in dev environment with device PaloAlto-026701009584.

[dev-iad3] [k8s:uc_iad3_dev](panos-inspect-lldp-ports) khackwor understack % baremetal port list --node PaloAlto-026701009945 -f value -c UUID | xargs -I {} baremetal port delete {}

Deleted port 0e5f72bd-da52-47f7-984f-f71f3f0f0e2e
Deleted port 32734424-cefa-4ebc-b22f-f8693075418a
[dev-iad3] [k8s:uc_iad3_dev](panos-inspect-lldp-ports) khackwor understack %
[dev-iad3] [k8s:uc_iad3_dev](panos-inspect-lldp-ports) khackwor understack % openstack baremetal node inspect PaloAlto-026701009945

# waiting 2 or so minutes

[dev-iad3] [k8s:uc_iad3_dev](panos-inspect-lldp-ports) khackwor understack %
[dev-iad3] [k8s:uc_iad3_dev](panos-inspect-lldp-ports) khackwor understack % openstack baremetal port list --node  PaloAlto-026701009945 --long -f json | jq '.[] | {address, local_link_connection}'
{
  "address": "60:15:2b:62:4a:10",
  "local_link_connection": {
    "port_id": "Ethernet1/43",
    "switch_id": "c4:7e:e0:e4:03:37",
    "switch_info": "f20-3-2.iad3.rackspace.net"
  }
}
{
  "address": "60:15:2b:62:4a:11",
  "local_link_connection": {
    "port_id": "Ethernet1/44",
    "switch_id": "c4:7e:e0:e4:03:37",
    "switch_info": "f20-3-2.iad3.rackspace.net"
  }
}

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Python test results

119 tests  ±0   119 ✅ ±0   1m 8s ⏱️ + 1m 1s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 69e49ba. ± Comparison against base commit 4a8be51.

♻️ This comment has been updated with latest results.

@khackworth
khackworth force-pushed the panos-inspect-lldp-ports branch from c1fc47f to 9e6c459 Compare October 23, 2026 15:13
@khackworth khackworth changed the title Add LLDP port discovery to PAN-OS inspect interface feat(panos): add LLDP port discovery to PAN-OS inspect interface Oct 23, 2026
@khackworth
khackworth force-pushed the panos-inspect-lldp-ports branch 4 times, most recently from 5632021 to d76ad65 Compare October 23, 2026 18:57
@khackworth
khackworth marked this pull request as ready for review October 23, 2026 19:04
@khackworth
khackworth enabled auto-merge October 23, 2026 19:04
Adds automatic network port discovery to PAN-OS firewalls during
inspection using LLDP neighbor discovery.

Implementation:
1. Removes factory default zone and virtual-wire configurations that
   would block interface configuration
2. Enables LLDP globally and configures it on all physical interfaces
3. Waits 30 seconds for LLDP neighbor discovery
4. Creates Ironic ports with local_link_connection metadata including:
   - switch_id (chassis ID)
   - port_id (remote port identifier)
   - switch_info (normalized FQDN switch name)
5. Derives VLAN groups from switch names using existing conventions
6. Removes temporary LLDP configuration to clean up

Port creation:
- Handles re-inspection gracefully by checking for existing ports
  by both MAC address and port name
- Normalizes switch names to FQDN format (adds .rackspace.net suffix)
  to match baremetal server port format
- Uses correct config group path for switch_name_vlan_group_mapping

IMPORTANT: This modifies device configuration and deletes factory
default settings. It should ONLY run during initial enrollment when
the device is in 'manageable' state, before any production
configuration exists. The inspect interface is only called during
enrollment, never on already-configured devices.
- Remove virtual-wire config from each interface before configuring as layer3
- Only commit factory cleanup if we actually deleted something
- Check commit return values and fail loudly with proper errors
- Include job details in commit failure error messages

This fixes inspection failures on devices with virtual-wire interfaces
configured, where commits were silently failing and code continued anyway.
Security rules reference zones, so they must be deleted first to avoid
validation errors when cleaning up factory/staging config for LLDP discovery.

This allows inspect to work on devices that have been through a staging
station that adds generic security rules.
Simplified LLDP discovery to configure all interfaces instead of trying
to detect which ones are already configured. Since the device must be in
manageable (not production) state, we can be destructive and just blast
through all interfaces.

This fixes the issue where ethernet1/1 and ethernet1/2 had virtual-wire
config that was detected as 'configured', causing them to be skipped,
which meant they never got LLDP enabled.
- Remove verbose DEBUG logs showing full XML responses and config operations from panos_api.py
- Remove per-interface deletion logs (22 lines per run)
- Add single summary log showing which factory configs were deleted
- Use contextlib.suppress for cleaner exception handling
- Keep essential INFO logs for key events (neighbor discovery, port creation)
Ruff S110 requires specific exception types instead of bare except Exception.
This also improves error handling by only catching the expected exception type.
@khackworth
khackworth force-pushed the panos-inspect-lldp-ports branch from d76ad65 to 924db13 Compare October 23, 2026 20:08
…l-fw

Port Category Assignment (LLDP Discovery):
- Assign 'outside'/'inside' categories to discovered firewall ports
- Sort ports by interface number (e.g., ethernet1/1 < ethernet1/2)
- For exactly 2 ports: lowest=outside, highest=inside
- For 3+ ports: first two get outside/inside, rest get no category
- For 1 port: no category assigned

Make --ports Optional (enroll-fw):
- Change --ports from required to optional with default []
- Update help text to clarify LLDP discovery is the primary method
- --ports now serves as override for cases where LLDP doesn't work
- Backward compatible: existing calls with --ports still work

This enables automatic firewall provisioning without manual port specification.
@khackworth
khackworth force-pushed the panos-inspect-lldp-ports branch from 4aed907 to ebc2a0f Compare October 27, 2026 12:07
… assigned

- Add CUSTOM_NETDEV_ROLE_ATTACH trait when port categories (outside/inside) are assigned
- Remove trait when no categories are assigned
- Uses proper Ironic objects API: objects.Trait.create() and objects.Trait.destroy()
- Addresses feedback from PR #2578 (netdev role attachment integration)
Changes interface sorting to match Nidhi's reconciler implementation:
- Uses re.split(r'(\d+)', name) to split on ALL digits, not just the last one
- Creates tuples for natural sorting (0, digit) or (1, string)
- Correctly sorts ethernet1/20 before ethernet2/19 (slot takes precedence)
- Previously only looked at port number, incorrectly sorting ethernet2/19 first

This ensures port category assignment in inspect matches enroll-fw exactly.
Validates minimum requirements before marking firewall as manageable:
- Requires at least 2 ports (outside/inside) - no 1-armed firewalls
- Warns if PA-1410 uses slow 1G ports (eth1/1-18) instead of 10G (eth1/19-22)
- Validates port categories were assigned correctly

The < 2 ports check fails fast before port creation and is outside the
exception handler so it properly raises HardwareInspectionFailure.

Validation only runs if port discovery succeeded - if LLDP fails, we
still return manageable with a warning (existing behavior preserved).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant